from flask import Blueprint, request
from flask_restful import Api, Resource

from utils.render import json_detail_render
from webapp.config.api_utils import oper_log, check_auth
from webapp.service.course_schedule_service import CourseScheduleService

course_schedule_app = Blueprint('schedule', __name__, url_prefix='/api/course/schedule')
course_schedule_api = Api(course_schedule_app)


@course_schedule_api.resource("", "/<int:id>")
class CoptionsApi(Resource):
    @oper_log('为课程进行排课', request)
    @check_auth('course:list', request)
    def post(self, id):
        CourseScheduleService.arrangeSchedule(id)
        return json_detail_render(0, message="课程安排已完成，请到课程看板查看该课程的相关安排")
